<template>
	<view class="content">
        <u-navbar
            bgColor="#fff" :fixed="true" :shadow="true"
            :safeAreaInsetTop="true" :placeholder="true"
            leftIconColor="#151C24"
            title="单位详情" titleColor="#151C24"
            @leftClick="back">
        </u-navbar>
        <view class="uni-area">
            <!-- 单位信息 -->
            <view class="u-m-t-30 uni-shadow u-p-b-10">
                <view class="u-m-b-20 u-flex u-row-between">
                    <view class="u-font-32 font-bold">项目信息</view>
                    <!-- <u-button class="uni-look-btn"
                        type="warning" :plain="true" shape="circle" text="" @tap="detail">
                        <text class="u-font-24">查看单位</text>
                    </u-button> -->
                </view>
                <view v-for="(item,index) in units" :key="index"
                    class="u-flex u-row-between u-p-t-20 u-p-b-20 u-font-28 item">
                    <text class="uni-dec-color">{{item.title}}</text>
                    <uni-phone v-if="item.type=='phone'" :phone="item.value" :size="14" />
                    <text v-else style="max-width:78%">{{item.value}}</text>
                </view>
            </view>
            <!-- 附件 -->
            <uni-accessory class="u-m-t-30" :accessorys="accessoryList"></uni-accessory>
        </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
                type: 'unit', // unit参建单位 subUnit分包单位
                // 单位信息
                units:[
                    { filed:'fbDwmc', title:'单位名称', value:'安薪乐' },
                    { filed:'tyshxydm', title:'统一社会信用代码', value:'安薪乐' },
                    { filed:'qydz', title:'单位地址', value:'安薪乐' },
                    { filed:'djzclx', title:'单位类型', value:'安薪乐' },
                    { filed:'districtName', title:'属地', value:'安薪乐' },
                    { filed:'zhuxiangzizhi', title:'主项资质类别', value:'安薪乐' },
                    { filed:'grade', title:'资质等级', value:'安薪乐' },
                    { filed:'grade', title:'资质证书号', value:'安薪乐' },
                    { filed:'buildingleaderphone', title:'联系电话', value:'安薪乐', type:'phone' },
                    { filed:'', title:'传真', value:'安薪乐' },
                    { filed:'fblx', title:'分包类型', value:'安薪乐' },
                    { filed:'htzj', title:'合同造价', value:'安薪乐' },
                    { filed:'fbbdmc', title:'分包标段名称', value:'安薪乐' },
                    { filed:'kgsj', title:'开工日期', value:'安薪乐' },
                    { filed:'jgsj', title:'竣工日期', value:'安薪乐' },
                ],
                // 附件
                accessoryList:[],
			}
		},

		onLoad(option) {
            if( option.type == 'unit' ){
                // console.log('参建单位')
                const api = JSON.parse(JSON.stringify(this.$apis.proProjectDetail))
                api.url = api.url+'/'+option.id
                this.getData(api,{})
            }else{
                // console.log('分包单位')
                const api = this.$apis.subUnitDeatail
                this.getData(api,{id:option.id})
            }
            // 获取附件
            this.getProAccessory(option.id)
		},

		methods: {
            // 返回
            back(){
                uni.navigateBack()
            },

            // 获取单位详情
            getData(api,parameter){
                uni.showLoading({ title:'数据加载中' })
                this.$request(this,api,parameter).then(res=>{
                    // console.log('单位详情',res)
                    this.units.map((v,i)=>{
                        if( v.filed == '' ){
                            v.value = '接口为返回字段'
                        }else if(v.filed=='htzj'){
                            v.value = res[v.filed]||res[v.filed]==0?res[v.filed]+'万元':'暂无数据源'
                        }else{
                            v.value = res[v.filed]?res[v.filed]:'暂无数据源'
                        }
                        
                    })
                }).then()
            },

            // 获取附件
            getProAccessory(ywbh){
                uni.showLoading({ title:'附件信息加载中' }) 
                const parameter = {
                    ywlx: 'salary_xmgl_fb', // 业务类型【必传】
                    ywbh: ywbh, // 业务编号【必传】
                }
                this.$request(this, this.$apis.CommonFjList, parameter).then(res=>{
                    // console.log('项目附件',res)
                    this.accessoryList = res
                }).then() 
            }
		}
	}
</script>

<style scoped lang="scss">
    .content{
        background: #FBFCFC;
        padding-bottom: 60rpx;
        .item{
            border-bottom: 1rpx solid #eee;
            &:last-child{
                border: none;
            }
        }
    }
</style>
